define([
    'jquery',
    'underscore',
    'backbone',
    'modelbinding',
    'app',
    'text!templates/business/item.html'
], function($, _, Backbone, ModelBinding, App, ModalConfirmView, template) {

    return Backbone.View.extend({
        tagName: 'tr',
        template : _.template(template),
        events: {
            /*'click a.delete' : 'delete',*/
            'click a.view'   : 'view'
          /*  'click a.edit'   : 'edit'*/
        },

        initialize: function(options) {
            _.bindAll(this, 'render','confirmDelete');

            this.model.on('error', this.error);
            /*this.model.on('modal:confirm', this.confirmDelete);*/

            $.when(this.model)
                .done(this.render);
        },

        render: function(template) {
            var self = this;
            $.when.apply(null, this.model).done(function() {
                self.$el.html(self.template({
                    model    : self.model.toJSON()
                }));
            });
            return this;
        },

        view: function(event){
            event.preventDefault();
            App.vent.trigger('business:view', this.model);
        },

       /* edit: function(event){
            event.preventDefault();
            App.vent.trigger('business:edit', this.model);
        },*/

        /*delete: function(event) {
            event.preventDefault();

            *//*var modalConfirmView = new ModalConfirmView({
                model  : this.model,
                header : 'Confirm Delete',
                body   : 'Are you sure you want to delete this item?'
            });*//*
            $('.head').html(modalConfirmView.render().el);
        },
*/
        /*confirmDelete: function() {
            $.when(this.model.destroy()).done(this.close);
        },*/

        error: function(model, response) {
            App.vent.trigger('alert', {
                msg: response.responseText ? response.responseText : response.statusText,
                type: 'error'
            });
        },

        close: function() {
            this.model.off('error', this.error);
            this.model.off('modal:confirm', this.confirmDelete);
            this.undelegateEvents();
            this.remove();
        }
    });
});
